package com.example.administrator.viewpaerdemo.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * Created by Administrator on 2018/8/27.
 */

public class BFragment extends Fragment {


    private TextView textView;
    private String string;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        Log.e("TAG", "BFragment==onAttach");
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        textView = new TextView(getContext());
        return textView;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (savedInstanceState == null) {
            savedInstanceState = getArguments();
        }
        string = savedInstanceState.getString("string");
        Log.e("TAG", "BFragment==onCreateView" + string);
        textView.setText(string);
    }

    @Override
    public void onDetach() {
        super.onDetach();

        Log.e("TAG", "BFragment==onDetach" + string);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.e("TAG", "BFragment==onDestroyView" + string);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.e("TAG", "BFragment==onDestroy");
    }

    public static Fragment getInstence(int i) {
        BFragment bFragment = new BFragment();
        Bundle bundle = new Bundle();
        bundle.putString("string", String.valueOf(i));
        bFragment.setArguments(bundle);
        return bFragment;
    }
}
